package com.sz.exce.controller;

import com.sz.exce.entity.Info;
import com.sz.exce.entity.Suspect;
import com.sz.exce.service.InfoService;
import com.sz.exce.service.SuspectService;
import com.sz.exce.vo.ExceQueryVo;
import com.sz.exce.vo.PageVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.UUID;


@RestController
public class InfoController {
    @Autowired
    InfoService infoService;
    @Autowired
    SuspectService suspectService;

    @Scheduled(cron = "0 0 0 * * ?")
    @GetMapping("/exce/auto")
    public void getExce(){
       List<Info> infos = infoService.getInfos();
        for (Info info:infos) {
            if (info.getNumCount()>5){
                Suspect suspect =  suspectService.querySuspect(info.getUsername());
                if (suspect == null){
                    Suspect suspect1 = new Suspect();
                    suspect1.setSuspectId(UUID.randomUUID().toString());
                    suspect1.setSuspectCount(1L);
                    suspect1.setSuspectStatus(1001L);
                    suspect1.setSuspectType("标记可能为洗黑钱");
                    suspect1.setUserid(info.getUsername());
                    suspectService.addSuspect(suspect1);
                }else {
                   Long temp = suspect.getSuspectCount()+1;
                   suspect.setSuspectCount(temp);
                   suspect.setUserid(info.getUsername());
                   suspect.setSuspectStatus(1001L);
                   suspectService.modifySuspectCount(suspect);
                }
            }
        }
    }
    @PostMapping("/exec/modify/{name}")
    public String modifyStatus(@PathVariable("name") String name){
        System.out.println(name);
        Suspect suspect = new Suspect();
        suspect.setUserid(name);
        suspect.setSuspectStatus(1002L);
        suspectService.modifyStatus(suspect);
        return "success";
    }
    @PostMapping("/exec/cancel/{name}")
    public String cancelStatus(@PathVariable("name") String name){
        System.out.println(name);
        Suspect suspect = new Suspect();
        suspect.setUserid(name);
        suspect.setSuspectStatus(1001L);
        suspectService.modifyStatus(suspect);
        return "success";
    }
    @PostMapping("/exec/find/all")
    public ExceQueryVo getExecFindAll(@RequestBody  PageVO vo){
        return suspectService.querySuspect(vo);
    }
}
